﻿<% include header.ejs %>

<body class="login login-action-register wp-core-ui locale-zh-cn">
	
	<div class="row">
		<div class="col-md-4"></div>
		<div class="col-md-4">
		<div id="login" class="well mybody2">
		<h1>欢迎注册顶上前端</h1>
		<p class="message register">在这个站点注册</p>
		<form name="registerform" id="registerform">
			<p> <label for="user_login">用户名<br /> <input type="text" name="user_login" id="user_login" class="input form-control" value="" size="20" /></label> </p>

			<p>
			<p> <label for="email">邮箱<br /> <input type="email" name="email" id="email" class="input form-control" value="" size="20" /></label> </p>

			<p>
				<label for="user_pwd1">密码(至少6位)<br/> <input id="user_pwd1" class="input form-control" type="password" size="25" value="" name="user_pass" /> </label></p>
			<p>
				<label for="user_pwd2">重复密码<br/> <input id="user_pwd2" class="input form-control" type="password" size="25" value="" name="user_pass2" /> </label></p>

			
			<p class="submit">
				<input type="button" name="wp-submit" id="wp-submit" class="btn btn-inverse-primary" value="注册" />
			</p>
		</form>
		<p id="nav">
			<a href="/list" class="btn btn-inverse-primary">登录</a> |
		<!--	<a href="#wp-login.php?action=lostpassword">忘记密码？</a>-->
		</p>
		<p id="backtoblog">
			<a href="/">&larr; 返回到首页</a>
		</p>
	</div>
		</div>
	<div class="col-md-4"></div>
	</div>

	
</body>

</html>
<% include alert.ejs %>
<% include footer.ejs %>
<script>
	jQuery('#wp-submit').click(function() {
		
		var ps1=jQuery('#user_pwd1').val()
		var ps2=jQuery('#user_pwd2').val()
		var email=jQuery('#email').val()
		var emailr=/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
		if(ps1==''){
			jQuery(".alertw .tit2 h4").html('请输入密码')
			jQuery(".alertw").show()
			return
		}else if (ps1!=ps2) {
			jQuery(".alertw .tit2 h4").html('两次密码不一致')
			jQuery(".alertw").show()
			return
		}else if(emailr.test(email)==false){
			jQuery(".alertw .tit2 h4").html('邮箱格式不对')
			jQuery(".alertw").show()
			return
		}
		
		jQuery.post("/reg/doreg", {
			"username": jQuery('#user_login').val(),
			"password": jQuery("#user_pwd1").val(),
			"email":jQuery("#email").val()
		}, function(res) {
			if(res == "1") {
				//注册成功
				//  alert("注册成功！将自动跳转到首页");
				window.location = '<%=nowurl%>'
			} else if(res == "-1") {
				//用户名被占用
				jQuery(".alertw .tit2 h4").html('用户名被占用')
				jQuery(".alertw").show()
				
			}else if(res=='-2'){
				jQuery(".alertw .tit2 h4").html('请输入用户名')
				jQuery(".alertw").show()
			}else if(res == "-3") {
				//服务器错误
				jQuery(".alertw .tit2 h4").html('服务器错误')
				jQuery(".alertw").show()
			}
		})
	})
</script>
